package com.example.smartcity_jscs.network.ResultStates

/**
 * 密封类,用以封装结果集
 */
sealed class Resource<T>(
    val data: T? = null, val msg: String? = null,val throwable: Throwable?=null
) {

    class Success<T>(data: T) : Resource<T>(data, "请求成功")
    class Loading<T> : Resource<T>()
    class Failure<T>(message: String,cause:Throwable) : Resource<T>(null, message,cause)

    override fun toString(): String {
        return when (this) {
            is Success<*> -> "Success[data=$data]"
            is Failure <T>-> "Error[exception=$msg]"
            is Loading<T> -> "Loading"
        }
    }

}

